package com.mose.controller;

import com.mose.entity.CommonResult;
import com.mose.entity.Order;
import com.mose.service.OrderService;
import io.seata.spring.annotation.GlobalLock;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/order/create/{productId}/{count}/{money}")
    public CommonResult<?> create(@PathVariable("productId") Integer productId,
                                  @PathVariable("count") Integer count,
                                  @PathVariable("money") BigDecimal money) {
        Order order = new Order();
        order.setProductId(productId.longValue());
        order.setCount(count);
        order.setMoney(money);
        return orderService.create(order);
    }

    @GlobalTransactional
    @GlobalLock
    @GetMapping("/test")
    public String test() {
        return "test";
    }
}
